/*
 * NetworkEventData.h
 *
 *  Created on: Sep 13, 2011
 *      Author: erudhes
 */

#ifndef NETWORKEVENTDATA_H_
#define NETWORKEVENTDATA_H_
#ifdef __WXGTK__
#include <netinet/in.h>
#endif
#include <wx/wx.h>

class NetworkEventData
{
	public:
		enum DataType
		{
			INVALID,
			CONNECTING,
			CONNECTION_REJECT,
			MOUSE_DOWN,
			MOUSE_UP,
			MOUSE_MOTION,
		};
		// Constructors to create object when sending data
		NetworkEventData();
		NetworkEventData(DataType dataType, int x, int y, const wxChar* level = NULL);
		NetworkEventData(DataType dataType, const wxPoint& position, const wxString& level = wxString());
		// Constructor to create object when receiving data
		NetworkEventData(char* buffer);
		DataType getDataType() const;
		void setDataType(DataType dataType);
		int getX() const;
		void setX(int x);
		int getY() const;
		void setY(int y);
		wxString getLevel() const;
		void setLevel(const wxString& level);

	private:
		DataType mDataType;
		int mX;
		int mY;
		// Contains the name of the level. Only used when the client connects to the server
		char mLevel[256];
};

inline NetworkEventData::DataType NetworkEventData::getDataType() const
{
	return (DataType)ntohl(mDataType);
}

inline void NetworkEventData::setDataType(NetworkEventData::DataType dataType)
{
	mDataType = (DataType)htonl(dataType);
}

inline int NetworkEventData::getX() const
{
	return ntohl(mX);
}

inline void NetworkEventData::setX(int x)
{
	mX = htonl(x);
}

inline int NetworkEventData::getY() const
{
	return ntohl(mY);
}

inline void NetworkEventData::setY(int y)
{
	mY = htonl(y);
}

inline wxString NetworkEventData::getLevel() const
{
	return wxString(mLevel, wxConvUTF8);
}

inline void NetworkEventData::setLevel(const wxString& level)
{
	// Convert the string to UTF8 to get rid of endian-ness
	const wxCharBuffer charBuffer = level.ToUTF8();
	const char* tempLevel = charBuffer.data();

	memset(mLevel, 0, 256);
	strcpy(mLevel, tempLevel);
}


#endif /* NETWORKEVENTDATA_H_ */
